//
//  publishViewController.m
//  FastRunDemo
//
//  Created by 苟亚明 on 16/9/16.
//  Copyright © 2016年 苟亚明. All rights reserved.
//

#import "publishViewController.h"
#import "KPNaviViewController.h"
#import "GYMPublishButton.h"
#import "sendMessageViewController.h"
#import "sendRequestViewController.h"
@interface publishViewController ()
@property (nonatomic, strong) NSArray *arrayPic;
@property (nonatomic, strong) NSArray *arrayName;
@end

@implementation publishViewController
#pragma mark - viewLife
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    // 图片数组
    self.arrayPic = @[@"btn_publish_orders",
                      @"btn_publish_square",
                      @"btn_publish_life",
                      @"btn_publish_things",
                      @"btn_publish_lose",
                      @"btn_publish_activity",
                      @"btn_publish_consult"];
    
    self.arrayName = @[@"找人帮",@"我能帮",@"生活动态",@"闲置",@"失物招领",@"发布活动",@"咨询"];
    
    // 中间的6个按钮
    int maxCols = 3;
    CGFloat buttonW = 72;
    CGFloat buttonH = buttonW + 30;
    CGFloat buttonStartY = (GYMScreenH - 2 * buttonH) * 0.4;
    CGFloat buttonStartX = 20;
    CGFloat xMargin = (GYMScreenW - 2 * buttonStartX - maxCols * buttonW) / (maxCols - 1);
    for (int i = 0; i<self.arrayPic.count; i++) {
        GYMPublishButton *button = [[GYMPublishButton alloc] init];
        
        // 设置内容
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setTitle:self.arrayName[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:self.arrayPic[i]] forState:UIControlStateNormal];
        button.flog = i;
        // 发段子按钮注册单击事件
        [button addTarget:self action:@selector(publishButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        // 设置frame
        button.width = buttonW;
        button.height = buttonH;
        int row = i / maxCols;
        int col = i % maxCols;
        button.x = buttonStartX + col * (xMargin + buttonW);
        button.y = buttonStartY + row * buttonH;
        [self.view addSubview:button];
    }
    
}


#pragma make - action

- (void)publishButtonClick:(UIButton *)button
{
    
    if (button.flog %2 == 0) {
        sendMessageViewController *vc = [[sendMessageViewController alloc]init];
        KPNaviViewController *Navi = [[KPNaviViewController alloc]initWithRootViewController:vc];
    
        [self presentViewController:Navi animated:YES completion:nil];
    }else{
        sendRequestViewController *vc = [[sendRequestViewController alloc]init];
        
        KPNaviViewController *Navi = [[KPNaviViewController alloc]initWithRootViewController:vc];
        [self presentViewController:Navi animated:YES completion:nil];
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
